﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using bdxyit.com.RecruitmentAppSys.ViewModels;
using System.Web.Routing;
using System.Diagnostics;
using bdxyit.com.RecruitmentAppSys.BLL;
using bdxyit.com.RecruitmentAppSys.Models;

namespace bdxyit.com.RecruitmentAppSys.Controllers
{
    public class FamilyInfoController : Controller
    {
        //
        // GET: /FamilyInfo/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Details(string userId)
        {
             List<FamilyInfo>  family =  FamilyInfoBLL.GetFamilyInfoByUserId(userId);
             ViewBag.relationships = SystemInfoBLL.GetSystemInfoByCode("FamRelationship");
             return View(family);
        }

        public ActionResult Create(string userId)
        {
            FamilyInfo family = new FamilyInfo();
            family.UserID = userId;
            ViewBag.relationships = SystemInfoBLL.GetSystemInfoByCode("FamRelationship");
            return View(family);
        }


        [HttpPost]
        public ActionResult Create(FamilyInfo fi, FormCollection form)
        {
            try
            {
                   fi.Relationship = form["SysID"].ToString();
                    bool flag =  FamilyInfoBLL.CreateFamilyInfoList(fi);
                    return RedirectToAction("Index", "OperatMessage", new
                    {
                        nextOperate = "FamilyInfo=EducationInfo",
                        mess = "添加家庭成员",
                        id = fi.UserID
                    });
            }
            catch
            {
                return RedirectToAction("Index");
            }
        }
        public ActionResult Delete(string  userID)
        {
            try
            {
                bool flag = FamilyInfoBLL.RemoveFamilyInfoByUserId(userID);
                return RedirectToAction("Details", "FamilyInfo", new
                {
                    ID = userID
                });
            }
            catch
            {
                return RedirectToAction("Index");
            }
        }


        public ActionResult Edit(string userId,string fid)
        {

            FamilyInfo fi = FamilyInfoBLL.GetFamilyInfoByUserIdAndFid(userId,fid);
            return View(fi);
        }

        //
        // POST: 
        [HttpPost]
        public ActionResult Edit(FamilyInfo fi, FormCollection form)
        {
            try
            {
                fi.Relationship = form["SysID"].ToString();
                bool flag = FamilyInfoBLL.CreateFamilyInfoList(fi);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
